<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Rails::Generator::Scripts::Base</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Rails::Generator::Scripts::Base</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/railties/lib/rails_generator/scripts_rb.html">
                vendor/rails/railties/lib/rails_generator/scripts.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../../../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
<a href="../../Generator.html">Generator</a> scripts handle command-line
invocation. Each script responds to an invoke! class method which handles
option parsing and generator invocation.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001472">banner</a>&nbsp;&nbsp;
      <a href="#M001471">run</a>&nbsp;&nbsp;
      <a href="#M001473">usage_message</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="../Options.html">Options</a></span>
      </div>
    </div>

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001471" class="method-detail">
        <a name="M001471"></a>

        <div class="method-heading">
          <a href="#M001471" class="method-signature">
          <span class="method-name">run</span><span class="method-args">(args = [], runtime_options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Run the generator script. Takes an array of unparsed arguments and a hash
of parsed arguments, takes the generator as an option or first remaining
argument, and invokes the requested command.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001471-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001471-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/scripts.rb, line 17</span>
17:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>(<span class="ruby-identifier">args</span> = [], <span class="ruby-identifier">runtime_options</span> = {})
18:           <span class="ruby-keyword kw">begin</span>
19:             <span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">args</span>.<span class="ruby-identifier">dup</span>, <span class="ruby-identifier">runtime_options</span>)
20:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">OptionParser</span><span class="ruby-operator">::</span><span class="ruby-constant">InvalidOption</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
21:             <span class="ruby-comment cmt"># Don't cry, script. Generators want what you think is invalid.</span>
22:           <span class="ruby-keyword kw">end</span>
23: 
24:           <span class="ruby-comment cmt"># Generator name is the only required option.</span>
25:           <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:generator</span>]
26:             <span class="ruby-identifier">usage</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>
27:             <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:generator</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">shift</span>
28:           <span class="ruby-keyword kw">end</span>
29: 
30:           <span class="ruby-comment cmt"># Look up generator instance and invoke command on it.</span>
31:           <span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generator</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">instance</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:generator</span>], <span class="ruby-identifier">args</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">command</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:command</span>]).<span class="ruby-identifier">invoke!</span>
32:         <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
33:           <span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>
34:           <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;  #{e.backtrace.join(&quot;\n  &quot;)}\n&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:backtrace</span>]
35:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">SystemExit</span>
36:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M001472" class="method-detail">
        <a name="M001472"></a>

        <div class="method-heading">
          <a href="#M001472" class="method-signature">
          <span class="method-name">banner</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Override with your own script usage <a href="Base.html#M001472">banner</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001472-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001472-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/scripts.rb, line 40</span>
40:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">banner</span>
41:             <span class="ruby-node">&quot;Usage: #{$0} generator [options] [args]&quot;</span>
42:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001473" class="method-detail">
        <a name="M001473"></a>

        <div class="method-heading">
          <a href="#M001473" class="method-signature">
          <span class="method-name">usage_message</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001473-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001473-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/railties/lib/rails_generator/scripts.rb, line 44</span>
44:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">usage_message</span>
45:             <span class="ruby-identifier">usage</span> = <span class="ruby-value str">&quot;\nInstalled Generators\n&quot;</span>
46:             <span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Generator</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">sources</span>.<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mem</span>, <span class="ruby-identifier">source</span><span class="ruby-operator">|</span>
47:               <span class="ruby-identifier">label</span> = <span class="ruby-identifier">source</span>.<span class="ruby-identifier">label</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">capitalize</span>
48:               <span class="ruby-identifier">mem</span>[<span class="ruby-identifier">label</span>] <span class="ruby-operator">||=</span> []
49:               <span class="ruby-identifier">mem</span>[<span class="ruby-identifier">label</span>] <span class="ruby-operator">|=</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">names</span>
50:               <span class="ruby-identifier">mem</span>
51:             <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">label</span>, <span class="ruby-identifier">names</span><span class="ruby-operator">|</span>
52:               <span class="ruby-identifier">usage</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;  #{label}: #{names.join(', ')}\n&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">names</span>.<span class="ruby-identifier">empty?</span>
53:             <span class="ruby-keyword kw">end</span>
54: 
55:             <span class="ruby-identifier">usage</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\nMore are available at http://rubyonrails.org/show/Generators\n  1. Download, for example, login_generator.zip\n  2. Unzip to directory \#{Dir.user_home}/.rails/generators/login\n     to use the generator with all your Rails apps\n&quot;</span>
56: 
57:             <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Object</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-identifier">:RAILS_ROOT</span>)
58:               <span class="ruby-identifier">usage</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;     or to \#{File.expand_path(RAILS_ROOT)}/lib/generators/login\n     to use with this app only.\n&quot;</span>
59:             <span class="ruby-keyword kw">end</span>
60: 
61:             <span class="ruby-identifier">usage</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;  3. Run generate with no arguments for usage information\n       \#{$0} login\n\nGenerator gems are also available:\n  1. gem search -r generator\n  2. gem install login_generator\n  3. \#{$0} login\n\n&quot;</span>
62:             <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">usage</span>
63:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>